package jdbctest;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by Administrator on 2017/9/11.
 */
public class InsertTest {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1、加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2、连接数据库
        Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3307/jdbc","root","123456");
        //3、获得statement
        Statement statement=conn.createStatement();
        //4、执行sql（表中插入一条数据）
        String sql="insert into users(id,name,alexa) values(6,'jbm',16)";
        // update  insert   delete 的sql语句执行要用executeUpdate()方法
        statement.executeUpdate(sql);
    }
}
